package cn.iocoder.yudao.module.ride.service.bindlog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ride.controller.admin.bindlog.vo.*;
import cn.iocoder.yudao.module.ride.dal.dataobject.bindlog.BindLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ride.dal.mysql.bindlog.BindLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.ride.enums.ErrorCodeConstants.*;

/**
 * 车辆绑定/解绑记录 Service 实现类
 *
 * @author 小胡同学
 */
@Service
@Validated
public class BindLogServiceImpl implements BindLogService {

    @Resource
    private BindLogMapper bindLogMapper;

    @Override
    public Long createBindLog(BindLogSaveReqVO createReqVO) {
        // 插入
        BindLogDO bindLog = BeanUtils.toBean(createReqVO, BindLogDO.class);
        bindLogMapper.insert(bindLog);

        // 返回
        return bindLog.getId();
    }

    @Override
    public void updateBindLog(BindLogSaveReqVO updateReqVO) {
        // 校验存在
        validateBindLogExists(updateReqVO.getId());
        // 更新
        BindLogDO updateObj = BeanUtils.toBean(updateReqVO, BindLogDO.class);
        bindLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteBindLog(Long id) {
        // 校验存在
        validateBindLogExists(id);
        // 删除
        bindLogMapper.deleteById(id);
    }

    @Override
        public void deleteBindLogListByIds(List<Long> ids) {
        // 删除
        bindLogMapper.deleteByIds(ids);
        }


    private void validateBindLogExists(Long id) {
        if (bindLogMapper.selectById(id) == null) {
            throw exception(BIND_LOG_NOT_EXISTS);
        }
    }

    @Override
    public BindLogDO getBindLog(Long id) {
        return bindLogMapper.selectById(id);
    }

    @Override
    public PageResult<BindLogDO> getBindLogPage(BindLogPageReqVO pageReqVO) {
        return bindLogMapper.selectPage(pageReqVO);
    }

}